//	ID: 066498650
//	Exercise #: 2
//	By:	Roy Moore
//
//	Written:	19/12/2011
//	Environment : VS2010
//
//-UDPTime.h-
//
//*Please include "ws2_32.lib" in the library list.

#ifndef __UDPTIME_H
#define __UDPTIME_H
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <winsock2.h> 
#include <string.h>
#include <time.h>
#include <windows.h>
using namespace std;
//------------------Constants-----------------------------------------------
#define TIME_PORT	27015
#define BUFFER_SIZE 255
#define NUMOFSERVICES 7
#define SAMPLECOUNT 100
//------------------Globals-------------------------------------------------
extern string serviceName[NUMOFSERVICES];
//------------------Enums---------------------------------------------------
enum ROLE { Server, Client}; // Defines the application instance role
enum MODE { Send, Recive}; // Defines the data flow direction
//------------------Structures----------------------------------------------
typedef struct msgInfo{
	int bytesSent;
    int bytesRecv;
	char sendBuff[BUFFER_SIZE];
	char recvBuff[BUFFER_SIZE];
} MsgInfo;
//------------------Prototypes----------------------------------------------
void InitserviceName();
SOCKET InitUDPConnection();
void BindSocketForServer(SOCKET connSocket);
MsgInfo InitMsgInfo();
void RecvDataFrom(SOCKET connSocket, MsgInfo *info, sockaddr * from_addr);
void SendDataTo(SOCKET connSocket, MsgInfo *info, sockaddr * to_addr);
void RecvData(SOCKET connSocket, MsgInfo *info);
void ExitAndCloseSocket(SOCKET connSocket, int _code);
void PrintStatus(ROLE role, MODE mode, int bytes, char* buff);

#endif // __UDPTIME_H